import React, { Component } from 'react'

export default class App extends Component {
    state={
        myname:"huahua"
    }
    
    // 相当于componentWillMount,初始化，适用于第一次和后续需要自身更新的逻辑
    static getDerivedStateFromProps(nextPros,nextState){
        console.log("getDerivedStateFromPros",nextState);
        return{
            myname:nextState.myname.substring(0,1).toUpperCase()+nextState.myname.substring(1)
        }
    }
  render() {
    return (
      <div>
        <button onClick={()=>{
            // this.setState({
                // myname:"Huahua"
            // })
        }}>
            click
        </button>
        {this.state.myname}
      </div>
    )
  }
}
